/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MOs.strategy.finiteDifference.DAO;

import MOs.strategy.finiteDifference.bean.*;
import controller.java.Petri;

/**
 *
 * @author Erick Rubio Mendoza
 */
public class finiteDifferenceMODAO {
    public void MOAnalysis(finiteDifferenceMO oFDMO){
        Petri petri = Petri.getInstance();
        
        int enemies;
        enemies=0;
        
        int friends;
        friends=0;
        
        finiteDifferenceMO oFDWeakEnemyMO = new finiteDifferenceMO();
        oFDWeakEnemyMO.setX(oFDMO.getX());
        oFDWeakEnemyMO.setY(oFDMO.getY());
        oFDWeakEnemyMO.setEne(oFDMO.getEne());
                
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                if (i!=0 && j!=0)
                {    
                    if (petri.getOpponent(oFDMO.getX()+i, oFDMO.getY()+j)>0) 
                    {
                        enemies++;
                        if (petri.getEnergy(oFDMO.getX()+i, oFDMO.getY()+j)<oFDWeakEnemyMO.getEne())
                        {
                            oFDWeakEnemyMO.setX(oFDMO.getX()+i);
                            oFDWeakEnemyMO.setY(oFDMO.getY()+j);
                            oFDWeakEnemyMO.setEne(petri.getEnergy(oFDMO.getX()+i, oFDMO.getY()+j));    
                            System.out.println("enemigo debil: (" + oFDMO.getX() + "," + oFDMO.getY() + ") ---> ("+oFDMO.getX()+i+"," + oFDMO.getY()+j+")");
                            oFDMO.setMode(1);                            
                        }    
                    }
                    else if (petri.getOpponent(oFDMO.getX()+i, oFDMO.getY()+j)==0)
                    {
                        friends++;
                    }
                }   
            }
        }    
        
        oFDMO.setEne(petri.getEnergy(oFDMO.getX(),oFDMO.getY()));
        oFDMO.setNutrient(petri.getNutrient(oFDMO.getX(),oFDMO.getY()));        
        oFDMO.setNeighborsEnemies(enemies);
        oFDMO.setNeighborsFriends(friends);
        oFDMO.setWeakEnemy(oFDWeakEnemyMO);
        
        
    }
    

}
